Course Introduction
Old Dominion University
Sequential measurements or values of a single entity over time.
Why study time series data?
“Predict” outcomes of a time series in future (unobserved) periods.
\[Y_{t} = f(Y_{t-1}, X_{t}, X_{t-1}, \tau_t, C_t, S_t)\] where:
Define Problem
What am I trying to solve?
Gather Data
FRED, WRDS, Etc.
Exploratory Data Analysis (EDA)
Plot, Plot, Plot
Choose & Fit a Model
\(Y_{t} = f(Y_{t-1}, X_{t}, X_{t-1}, \tau_t, C_t, S_t)\)
Evaluate, Forecast
table()aggregate()match()paste(), paste0(), substr(), grepl(), gsub(), regexpr(), strsplit(), unlist()for()if(), elseifelse()fixestscales::alpha()data.table::fread()readRDS(), saveRDS()lubridate1tsibbleforecastts()2duplicated() date urate_t
1 1948-01-01 3.4
2 1948-02-01 3.8
3 1948-03-01 4.0
4 1948-04-01 3.9
5 1948-05-01 3.5
6 1948-06-01 3.6
date urate_t
1 1948-01-01 3.4
2 1948-02-01 3.8
3 1948-03-01 4.0
4 1948-04-01 3.9
5 1948-05-01 3.5
6 1948-06-01 3.6
date urate_t urate_tm1 urate_tp1
1 1948-01-01 3.4 NA 3.8
2 1948-02-01 3.8 3.4 4.0
3 1948-03-01 4.0 3.8 3.9
4 1948-04-01 3.9 4.0 3.5
5 1948-05-01 3.5 3.9 3.6
6 1948-06-01 3.6 3.5 3.6
state year var
1 NY 2010 0.98176529
2 NY 2011 -0.04575189
3 NY 2012 1.73884110
11 VA 2010 -1.23379611
12 VA 2011 -0.97220151
13 VA 2012 -1.20317155
21 CA 2010 0.06060990
22 CA 2011 0.68533755
23 CA 2012 0.48815305
state year var var_lag1
1 NY 2010 0.98176529 NA
2 NY 2011 -0.04575189 NA
3 NY 2012 1.73884110 NA
11 VA 2010 -1.23379611 NA
12 VA 2011 -0.97220151 NA
13 VA 2012 -1.20317155 NA
21 CA 2010 0.06060990 NA
22 CA 2011 0.68533755 NA
23 CA 2012 0.48815305 NA
state year var var_lag1
1 NY 2010 0.98176529 NA
2 NY 2011 -0.04575189 0.98176529
3 NY 2012 1.73884110 -0.04575189
11 VA 2010 -1.23379611 NA
12 VA 2011 -0.97220151 -1.23379611
13 VA 2012 -1.20317155 -0.97220151
21 CA 2010 0.06060990 NA
22 CA 2011 0.68533755 0.06060990
23 CA 2012 0.48815305 0.68533755
lim <- df$state == "NY"
plot(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)),
type = "l")
lim <- df$state == "VA"
lines(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)))
lim <- df$state == "CA"
lines(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)))plot(df$year, df$var, type = "n")
lim <- df$state == "NY"
lines(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)))
lim <- df$state == "VA"
lines(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)))
lim <- df$state == "CA"
lines(df$year[lim], df$var[lim],
col = match(df$state[lim], unique(df$state)))ECON 707/807: Econometrics II